package dataAccess;

import java.sql.ResultSet;
import java.sql.SQLException;

import exception.MyException;

public class IdTicketDB {

	public static int getMaxId() throws MyException{
		DBManager db;
		try {
			db = new DBManager();
		} catch (MyException e1) {
			throw e1;
		}
		String select = "SELECT MAX(IDTICKETS) maxid FROM IMM.TICKETS";	
		ResultSet rs;
		try {
			rs = db.executeAndReturn(select);			
			if (rs.next()){
				return rs.getInt("maxid");
			}
		} catch (SQLException e) {
			throw new MyException("Error en la Base datos al obtener registro.");
		}catch (MyException e) {
			throw e;
		}finally{
			db.close();
		}			
		return 0;
	}
	
	public static int getMaxAnulationId() throws MyException{
		DBManager db;
		try {
			db = new DBManager();
		} catch (MyException e1) {
			throw e1;
		}
		String select = "SELECT MAX(IDCANCEL) maxidcancel FROM IMM.TICKETS";
		ResultSet rs;
		try {
			rs = db.executeAndReturn(select);			
			if (rs.next()){
				return rs.getInt("maxidcancel");
			}
		} catch (SQLException e) {
			throw new MyException("Error en la Base datos al obtener registro.");
		}catch (MyException e) {
			throw e;
		}finally{
			db.close();
		}			
		return 0;
	}
	
}
